package leetcode;

/**
 * @author 榆关
 * 青蛙跳台阶
 */
public class recursion {
    //一次可以1，或2阶，跳上n阶有多少种办法
    public int jumpFloorI(int n){
        int preNum = 1;
        int prepreNum = 0;
        int result = 0;
        if(n <= 1){
            return n;
        }
        for(int i=2;i<=n;i++){
            result = preNum + prepreNum;
            prepreNum = preNum;
            preNum = result;
        }
        return result;
    }
    //一次可以跳1，2，...n阶，跳上n阶有多少种办法
    public int jumpFloorII(int n){
        if(n<=0){
            return -1;
        }else if(n == 1){
            return 1;
        } else {
            return 2 * jumpFloorII(n - 1);
        }
    }
}
